#pragma once

#include <list>
#include <vector>

using namespace std;

class OgreConsole:public Singleton<OgreConsole>,FrameListener{
public:
	OgreConsole();
	~OgreConsole();

	void	init(Ogre::Root *root);
	void	shutdown();

	void	setVisible(bool visible);
	bool	isVisible(){return visible;}

	void	print(const String &text);

	virtual bool frameStarted(const Ogre::FrameEvent &evt);
	virtual bool frameEnded(const Ogre::FrameEvent &evt);

	void onKeyPressed(OIS::KeyEvent *e);

	void addCommand(const String &command, void (*)(vector<String>&));
	void removeCommand(const String &command);

	//log
	virtual void write( const String& name,
					const String& message, 
					LogMessageLevel lml = LML_NORMAL, 
					bool maskDebug = false ){print(name+": "+message);}
private:
	bool				visible;
	bool				initialized;
	Ogre::Root			*root;
	Ogre::SceneManager	*scene;
	Ogre::Rectangle2D	*rect;
	Ogre::SceneNode		*node;
	Ogre::OverlayElement *textbox;
	Ogre::Overlay		*overlay;

	float				height;
	bool				update_overlay;
	int					start_line;
	list<String>		lines;
	String				prompt;
	map<String,void (*)(vector<String>&)>  commands;
};
